package com.lin.manager.controller.tool;

import com.lin.manager.aop.Log;
import com.lin.manager.common.enums.LogEnum;
import com.lin.manager.common.resp.R;
import com.lin.manager.tool.service.GeneratorCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author linjiang
 * @date 2024/5/15
 * @fn
 */
@Api(tags = "代码生成")
@RestController
@RequestMapping("gen")
public class GeneratorCodeController {

    @Autowired
    private GeneratorCodeService generatorCodeService;

    @ApiOperation("代码生成")
    @GetMapping("/downloadSingle")
    public R genSingleByTableId(Integer tableId, HttpServletResponse response) {
        generatorCodeService.genByTableId(1, tableId, response);
        return R.ok();
    }

    @ApiOperation("代码生成")
    @Log(module = "代码预览", descipt = "单张表代码预览", type = LogEnum.INSERT)
    @GetMapping("/preview")
    public R previewByTableId(Integer tableId) {
        generatorCodeService.previewByTableId(2, tableId);
        return R.ok();
    }

    @ApiOperation("代码生成")
    @GetMapping("/downloadMany")
    public R genManyByTableId(@RequestBody List<Integer> tableIds, HttpServletResponse response) {
        generatorCodeService.genManyByTableId(tableIds, response);
        return R.ok();
    }
}
